# delimit ;

drop _all;
clear;
clear matrix;
clear mata;
set more off;
set matsize 11000;
set maxvar 11000;

* Citation: Rangel, M. A. and T. Vogl 
"Agricultural Fires and Health at Birth"
The Review of Economics and Statistics;

******************************************************************************
ABSTRACT

Do file employs fires an pollution/weather measurement.

OFFICIAL SOURCES OF DATA:
INPE
CETESB

WE PROVIDE DATA IN STATA FORMAT:
fires_pollution.dta

******************************************************************************;

global data_repository "../RESTAT_data";
global logs_final "../RESTAT_logs";
global dofiles "../RESTAT_do";
local bootruns "249";

************************************************************************
Table 2 - causal inference fires and air pollution
************************************************************************;
 
use "$data_repository/fires_pollution.dta", clear;

xi, prefix(STA) noomit i.station_id;

xtset station_id date_BR;

xtsum PM10_dayavg_week0 NOx_dayavg_week0 O3_dayavg_week0;



foreach pollutant in PM10  {;

	foreach depvar in `pollutant'_dayavg_week {;

	* fully contemporaneous model  ;

		sum `depvar'0;
		
		reg	`depvar'0, cluster(station_id);
		outreg2 using "$logs_final/Table2_pollution_fires.out",  dec(6) noaster stats(coef se pval) replace;

		areg `depvar'0  
		znr_risks50_week0 nr_fires5_week0 
		STA*, absorb(date_BR) cluster(station_id);
		outreg2 using "$logs_final/Table2_pollution_fires.out",  dec(6) noaster stats(coef se pval) append;
		
		areg `depvar'0  
		znr_risks50_week0  nr_fires5_week0 
		RH_dayavg_week0  TEMP_dayavg_week0  
		RHTEMP_dayavg_week0  
		NNE_wind_week0 ENE_wind_week0 ESE_wind_week0 SSE_wind_week0 SSW_wind_week0 WSW_wind_week0 WNW_wind_week0 NNW_wind_week0 
		nowindmeas_week0 nonprvwinds_week0
		STA*, absorb(date_BR) cluster(station_id);
		outreg2 using "$logs_final/Table2_pollution_fires.out",  dec(6) noaster stats(coef se pval) append;
		
	
		preserve;

		log using "$logs_final/Table2_pollution_fires.log", replace;
	
	    set seed 20160817;
	
	
		adopath +  "$dofiles";


		wild_areg `depvar'0  znr_risks50_week0 
		,ivar(station_id) tvar(date_BR) 
		control(STA* nr_fires5_week0) 
		bootstraps(`bootruns');


		wild_areg `depvar'0  znr_risks50_week0 
		,ivar(station_id) tvar(date_BR) 
		control(nr_fires5_week0 RH_dayavg_week0  TEMP_dayavg_week0  RHTEMP_dayavg_week0  NNE_wind_week0 ENE_wind_week0 ESE_wind_week0 SSE_wind_week0 SSW_wind_week0 WSW_wind_week0 WNW_wind_week0 NNW_wind_week0 nowindmeas_week0 nonprvwinds_week0 STA*) 
		bootstraps(`bootruns');
			
		adopath -  "$dofiles";

		log close;
		
		restore;
		
		

	};
	
};



*** Introduces wind direction as additional element   ;



foreach pollutant in PM10 {;

	foreach depvar in `pollutant'_dayavg_week  {;

		foreach indepvar in risks {;
		
			foreach radius in 50 {;
		
		areg `depvar'0  

		zpv_nr_`indepvar'`radius'_week0
		zres_nr_`indepvar'`radius'_week0
				
		nr_fires5_week0 
		RH_dayavg_week0  TEMP_dayavg_week0  
		RHTEMP_dayavg_week0  
		NNE_wind_week0 ENE_wind_week0 ESE_wind_week0 SSE_wind_week0 SSW_wind_week0 WSW_wind_week0 WNW_wind_week0 NNW_wind_week0 
		nowindmeas_week0 nonprvwinds_week0
		STA*, absorb(date_BR) cluster(station_id);
		outreg2 using "$logs_final/Table2_pollution_fires.out", dec(6) noaster stats(coef se pval) append;
		
		areg `depvar'0  
		
		zpv_nr_`indepvar'`radius'_week0
		znr_`indepvar'`radius'_week0
				
		nr_fires5_week0 
		RH_dayavg_week0  TEMP_dayavg_week0  
		RHTEMP_dayavg_week0  
		NNE_wind_week0 ENE_wind_week0 ESE_wind_week0 SSE_wind_week0 SSW_wind_week0 WSW_wind_week0 WNW_wind_week0 NNW_wind_week0 
		nowindmeas_week0 nonprvwinds_week0
		STA*, absorb(date_BR) cluster(station_id);
		outreg2 using "$logs_final/Table2_pollution_fires.out", dec(6) noaster stats(coef se pval) append;

		
		areg `depvar'0  
		
		zpv_nr_`indepvar'`radius'_week0
		znr_`indepvar'`radius'_week0
				
		nr_fires5_week0 
		RH_dayavg_week0  TEMP_dayavg_week0  
		RHTEMP_dayavg_week0  
		NNE_wind_week0 ENE_wind_week0 ESE_wind_week0 SSE_wind_week0 SSW_wind_week0 WSW_wind_week0 WNW_wind_week0 NNW_wind_week0 
		nowindmeas_week0 nonprvwinds_week0
		STA*
		[aweight=wpop]
		, absorb(date_BR) cluster(station_id);
		outreg2 using "$logs_final/Table2_pollution_fires.out", dec(6) noaster stats(coef se pval) append;
		
		preserve;

		log using "$logs_final/Table2_pollution_fires.log", append;
	
	    set seed 20160817;
	
		adopath +  "$dofiles";

	    set seed 20160817;		
		wild_areg `depvar'0 zpv_nr_`indepvar'`radius'_week0	zres_nr_`indepvar'`radius'_week0
		,ivar(station_id) tvar(date_BR) 
		control(RH_dayavg_week0  TEMP_dayavg_week0  nr_fires5_week0 RHTEMP_dayavg_week0  NNE_wind_week0 ENE_wind_week0 ESE_wind_week0 SSE_wind_week0 SSW_wind_week0 WSW_wind_week0 WNW_wind_week0 NNW_wind_week0 nowindmeas_week0 nonprvwinds_week0 STA*) 
		bootstraps(`bootruns');

		set seed 20160817;
		wild_areg `depvar'0 zpv_nr_`indepvar'`radius'_week0	znr_`indepvar'`radius'_week0
		,ivar(station_id) tvar(date_BR) 
		control(RH_dayavg_week0  TEMP_dayavg_week0 nr_fires5_week0 RHTEMP_dayavg_week0  NNE_wind_week0 ENE_wind_week0 ESE_wind_week0 SSE_wind_week0 SSW_wind_week0 WSW_wind_week0 WNW_wind_week0 NNW_wind_week0 nowindmeas_week0 nonprvwinds_week0 STA*) 
		bootstraps(`bootruns');

		set seed 20160817;
		wild_areg `depvar'0 zpv_nr_`indepvar'`radius'_week0	znr_`indepvar'`radius'_week0
		[aweight=wpop]
		,ivar(station_id) tvar(date_BR) 
		control(RH_dayavg_week0  TEMP_dayavg_week0 nr_fires5_week0 RHTEMP_dayavg_week0  NNE_wind_week0 ENE_wind_week0 ESE_wind_week0 SSE_wind_week0 SSW_wind_week0 WSW_wind_week0 WNW_wind_week0 NNW_wind_week0 nowindmeas_week0 nonprvwinds_week0 STA*) 
		bootstraps(`bootruns');
		
		adopath -  "$dofiles";

		log close;
		
		restore;
		
		

			};
		};
	};
};	


foreach pollutant in NOx O3 {;

	foreach depvar in `pollutant'_dayavg_week  {;

		foreach indepvar in risks {;
		
			foreach radius in 50 {;
		
	
		areg `depvar'0  

		zpv_nr_`indepvar'`radius'_week0
		zres_nr_`indepvar'`radius'_week0
				
		nr_fires5_week0 
		RH_dayavg_week0  TEMP_dayavg_week0  
		RHTEMP_dayavg_week0  
		NNE_wind_week0 ENE_wind_week0 ESE_wind_week0 SSE_wind_week0 SSW_wind_week0 WSW_wind_week0 WNW_wind_week0 NNW_wind_week0 
		nowindmeas_week0 nonprvwinds_week0
		STA*, absorb(date_BR) cluster(station_id);
		outreg2 using "$logs_final/Table2_pollution_fires.out", dec(6) noaster stats(coef se pval) append;

		areg `depvar'0  
		
		zpv_nr_`indepvar'`radius'_week0
		znr_`indepvar'`radius'_week0
				
		nr_fires5_week0 
		RH_dayavg_week0  TEMP_dayavg_week0  
		RHTEMP_dayavg_week0  
		NNE_wind_week0 ENE_wind_week0 ESE_wind_week0 SSE_wind_week0 SSW_wind_week0 WSW_wind_week0 WNW_wind_week0 NNW_wind_week0 
		nowindmeas_week0 nonprvwinds_week0
		STA*, absorb(date_BR) cluster(station_id);
		outreg2 using  "$logs_final/Table2_pollution_fires.out", dec(6) noaster stats(coef se pval) append;

		areg `depvar'0  
		
		zpv_nr_`indepvar'`radius'_week0
		znr_`indepvar'`radius'_week0
				
		nr_fires5_week0 
		RH_dayavg_week0  TEMP_dayavg_week0  
		RHTEMP_dayavg_week0  
		NNE_wind_week0 ENE_wind_week0 ESE_wind_week0 SSE_wind_week0 SSW_wind_week0 WSW_wind_week0 WNW_wind_week0 NNW_wind_week0 
		nowindmeas_week0 nonprvwinds_week0
		STA*
		[aweight=wpop]
		, absorb(date_BR) cluster(station_id);
		outreg2 using  "$logs_final/Table2_pollution_fires.out", dec(6) noaster stats(coef se pval) append;

		
		
		preserve;

		log using "$logs_final/Table2_pollution_fires.log", append;
	
	    set seed 20160817;
	
		adopath + "$dofiles";

	    set seed 20160817;		
		wild_areg `depvar'0 zpv_nr_`indepvar'`radius'_week0	zres_nr_`indepvar'`radius'_week0
		,ivar(station_id) tvar(date_BR) 
		control(RH_dayavg_week0  TEMP_dayavg_week0  nr_fires5_week0 RHTEMP_dayavg_week0  NNE_wind_week0 ENE_wind_week0 ESE_wind_week0 SSE_wind_week0 SSW_wind_week0 WSW_wind_week0 WNW_wind_week0 NNW_wind_week0 nowindmeas_week0 nonprvwinds_week0 STA*) 
		bootstraps(`bootruns');

		set seed 20160817;
		wild_areg `depvar'0 zpv_nr_`indepvar'`radius'_week0	znr_`indepvar'`radius'_week0
		,ivar(station_id) tvar(date_BR) 
		control(RH_dayavg_week0  TEMP_dayavg_week0 nr_fires5_week0 RHTEMP_dayavg_week0  NNE_wind_week0 ENE_wind_week0 ESE_wind_week0 SSE_wind_week0 SSW_wind_week0 WSW_wind_week0 WNW_wind_week0 NNW_wind_week0 nowindmeas_week0 nonprvwinds_week0 STA*) 
		bootstraps(`bootruns');

		set seed 20160817;
		wild_areg `depvar'0 zpv_nr_`indepvar'`radius'_week0	znr_`indepvar'`radius'_week0
		[aweight=wpop]
		,ivar(station_id) tvar(date_BR) 
		control(RH_dayavg_week0  TEMP_dayavg_week0 nr_fires5_week0 RHTEMP_dayavg_week0  NNE_wind_week0 ENE_wind_week0 ESE_wind_week0 SSE_wind_week0 SSW_wind_week0 WSW_wind_week0 WNW_wind_week0 NNW_wind_week0 nowindmeas_week0 nonprvwinds_week0 STA*) 
		bootstraps(`bootruns');

		
		adopath -  "$dofiles";

		log close;
		
		restore;
		
		

			};
		};
	};
};	

		
exit; 